/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.freedom.imarket.util.converter;

import org.apache.commons.lang.StringUtils;

/**
 *
 * @author edoardo
 */
public class UnderscoreTableNameToHeaderConverter implements TableColumnNameConverter {

    @Override
    public String translate(String columnName) {
        if (columnName.indexOf("_") != -1) {
            String[] s = StringUtils.split(columnName, "_");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < s.length; i++) {
                String string = s[i].toLowerCase();
                if (i > 0) {
                    string = StringUtils.capitalize(string);
                }
                sb.append(string);
            }
            return sb.toString().trim();
        }
        return StringUtils.capitalize(columnName.toLowerCase());
    }
}
